import { createApp } from 'vue';
import './public-path.js';
import App from './App.vue';
import router from './router';

let app = null;

function render(props = {}) {
  const { container } = props;
  
  app = createApp(App);
  app.use(router);
  const dom = container ? container.querySelector('#app') : document.getElementById('app');
  app.mount(dom);
}

if (window.__POWERED_BY_QIANKUN__) {
  // eslint-disable-next-line no-undef
  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
} else {
  render();
}

export async function bootstrap() {
  console.log('[vue-app] vue app bootstraped');
}

export async function mount(props) {
  console.log('[vue-app] props from main framework', props);
  render(props);
}

export async function unmount() {
  if (app) {
    app.unmount();
    app = null;
  }
}